<template>
  <div class="component">
    <el-image @click="click" fit="cover" :src="coverUrl"></el-image>
    <div class="title">
      <el-link :underline="false">
        {{ title }}
      </el-link>
    </div>
    <div class="desc">
      <el-row>
        <el-col :span="16" class="left">
          <el-link :underline="false"> 授课教师：{{ realName }} </el-link>
        </el-col>
        <el-col :span="8" class="right"> {{ label }} </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { getById } from "@/api/common";

export default {
  props: {
    lessonId: {
      type: String,
      required: true,
    },
    teacherName: {
      type: String,
    },
    teacherId: {
      type: String,
    },
    title: {
      type: String,
      required: true,
    },
    coverUrl: {
      type: String,
    },
    label: {
      type: String,
    },
  },
  data() {
    return {
      loading: {
        fullScreen: undefined,
      },
      realName: this.teacherName,
    };
  },
  methods: {
    click() {
      this.loading.fullScreen = this.$loading(
        this.$store.state.fullScreeLoadingOption
      );

      const id = this.lessonId;
      getById("courseLesson", { id }).then((res) => {
        this.$store.dispatch("lesson/setCurrentLesson", res);
        this.loading.fullScreen.close();
        this.$router.push("/lessonDetail");
      });
    },
  },
  created() {
    if (this.teacherId !== undefined) {
      const id = this.teacherId;
      getById("user", { id }).then((res) => {
        this.realName = res.realName;
      });
    }
  },
};
</script>

<style lang="scss" scoped>
.component {
  width: 100%;
  height: 100%;
  border-radius: 1rem;

  &:hover {
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }

  .el-image {
    width: 100%;
    height: 70%;
    border-radius: 1rem;
    cursor: pointer;
  }

  .title {
    text-align: left;
    padding-left: 0.5rem;
    padding-top: 0.5rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;

    .el-link {
      font-size: 1.5rem;
      overflow-wrap: break-word;
      display: block;
    }
  }

  .desc {
    text-align: left;
    padding-left: 0.5rem;
    color: #afb2b8;
    font-weight: bold;
    font-size: 1rem;

    .left {
      padding-top: 0.3rem;
    }

    .right {
      text-align: right;
      padding-right: 0.5rem;
    }
  }
}
</style>